<template>
    <el-container class="content">
        <el-header :height="'auto'">
            <breadcrumb :title="'科室进出健康分析'" :noBack="true"></breadcrumb>
        </el-header>
        <el-main>
            <el-container class="white-block box full" v-loading="loading">
                <el-header :height="'auto'">
                    <div class="toolbar">
                        <div>
                            <el-select v-model="deptName" filterable placeholder="请选择科室" size="small" class="select"
                                       clearable>
                                <el-option
                                    v-for="item in deptList"
                                    :key="item.value"
                                    :label="item.name"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                            <el-date-picker v-model="searchTime" size="small" class="short mr10"
                                            type="daterange"
                                            range-separator="~"
                                            start-placeholder="开始日期"
                                            end-placeholder="结束日期">
                            </el-date-picker>
                            <el-button class="primary" @click="getList(1)" size="small">查询</el-button>
                            <el-button class="minor" @click="reset()" size="small">重置</el-button>
                            <!--                            <el-button @click="dataExport()" size="small">导出</el-button>-->
                        </div>
                    </div>
                </el-header>
                <el-main class="mt10">
                    <table-example ref="table" :data="tableData" :tableColumn="header" :stripe="true"
                                   :showSummary="true" :getSummaries="getSummaries" :height="'100%'">
                        <template slot="peopleType" slot-scope="scope">
                            <span v-if="scope.row.peopleType==1">患者</span>
                            <span v-if="scope.row.peopleType==2">家属</span>
                            <span v-if="scope.row.peopleType==3">本院人员</span>
                        </template>
                        <template slot="actionType" slot-scope="scope">
                            <span v-if="scope.row.actionType==1">进</span>
                            <span v-if="scope.row.actionType==2">出</span>
                        </template>
                    </table-example>
                </el-main>
                <el-footer :height="'auto'" class="mt20">
                    <page :data="page" @jumpPage="getList"></page>
                </el-footer>
            </el-container>
            <!--            <transition name="slide">-->
            <!--                <router-view @upload="getList"></router-view>-->
            <!--            </transition>-->
        </el-main>
    </el-container>
</template>

<script>
    import breadcrumb from '../components/breadcrumb'
    import tableExample from '../components/table'
    import page from '../components/pagination'

    export default {
        data() {
            return {
                deptName: '', // 部门名称
                searchTime: '',
                tableData: [],
                header: [
                    {
                        prop: 'type',
                        label: '科室',
                        minWidth: '100',
                        align: 'center'
                    },
                    {
                        prop: 'inNum',
                        label: '进门次数',
                        minWidth: '100',
                        align: 'center'
                    },
                    {
                        prop: 'healthInNumAcc',
                        label: '人员进门健康度',
                        minWidth: '150',
                        align: 'center'
                    },
                    {
                        prop: 'outNum',
                        label: '出门次数',
                        minWidth: '150',
                        align: 'center'
                    },
                    {
                        prop: 'healthOutNumAcc',
                        label: '人员出门健康度',
                        minWidth: '100',
                        align: 'center'
                    },
                    {
                        prop: 'sumNum',
                        label: '进出次数',
                        minWidth: '100',
                        align: 'center'
                    },
                    {
                        prop: 'sumHealthNumAcc',
                        label: '总体健康度',
                        align: 'center',
                        minWidth: '100'
                    }
                ],
                // slotColumns: ['peopleType', 'actionType'],
                page: {},
                index: 1,
                loading: false,
                deptList: [],
                sum: null
            }
        },
        mounted() {
            let start = this.$filter.timeFormat(null, 'YYYY-MM-DD HH:mm:ss'),
                end = this.$filter.timeFormat(null, 'YYYY-MM-DD HH:mm:ss')
            this.searchTime = [start, end]
            this.getDept()
            this.getList()
        },
        methods: {
            getDept() {
                this.$http.get('/thisCourt/hsDepartmentData').then(result => {
                    if (result.success) {
                        this.deptList = result.data
                    }
                })
            },
            // 获取列表数据
            getList(index) {
                this.loading = true
                if (index) this.index = index
                this.$http.get('/reportPeoplePass/getPerAnalysis', {
                    startTime: this.searchTime && this.searchTime[0] ? this.$filter.timeFormat(this.searchTime[0], 'YYYY-MM-DD') : '', // 起始时间
                    endTime: this.searchTime && this.searchTime[1] ? this.$filter.timeFormat(this.searchTime[1], 'YYYY-MM-DD') : '', // 结束时间
                    typeId: this.deptName,
                    current: this.index || 1,
                    size: 15
                }).then(result => {
                    this.loading = false
                    if (result.success) {
                        this.tableData = result.data.records[0].everyDepartmentEntryAndExit
                        this.sum = result.data.records[0].totalEntryAndExit
                        this.page = result.data
                        delete this.page['records']
                    }
                }).catch(() => {
                    this.loading = false
                })
            },
            // 重置操作
            reset() {
                let start = this.$filter.timeFormat(null, 'YYYY-MM-DD HH:mm:ss'),
                    end = this.$filter.timeFormat(null, 'YYYY-MM-DD HH:mm:ss')
                this.searchTime = [start, end]
                this.deptName = ''
                this.getList(1)
            },
            // 导出表格
            dataExport() {
                window.open(location.origin + '/_api/reportPeoplePass/downloadStaff', '_blank')
            },
            approval(row, type) {
                this.$http.post('/resumption/approval', {
                    id: row.id,
                    approvalResult: type
                }).then(result => {
                    this.getList()
                })
            },
            getSummaries(param) {
                let {columns} = param,
                    sums = [], _this = this
                if (_this.sum) {
                    columns.forEach((column, index) => {
                        if (index === 0) {
                            sums[index] = (_this.sum && _this.sum.type) || '合计'
                        } else if (index === 1) {
                            sums[index] = _this.sum.inNumCount || 0
                        } else if (index === 2) {
                            sums[index] = _this.sum.inHealthCountAcc || '0%'
                        } else if (index === 3) {
                            sums[index] = _this.sum.outNumCount || 0
                        } else if (index === 4) {
                            sums[index] = _this.sum.outHealthCountAcc || '0%'
                        } else if (index === 5) {
                            sums[index] = _this.sum.inAndOutCount || 0
                        } else if (index === 6) {
                            sums[index] = _this.sum.sumHealthNumAcc || '0%'
                        }
                    })
                }

                return sums
            }
        },
        components: {
            tableExample,
            page,
            breadcrumb
        }
    }
</script>

<style scoped lang="less">
    .content {
    }
</style>
